home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2010 April
/
PCWorld0410.iso
/
pluginy Firefox
/
1833
/
1833.xpi
/
chrome
/
yoono.jar
/
content
/
yoono
/
accountSelector.js
< prev
next >
Wrap
Text File
|
2009-12-16
|
15KB
|
411 lines
Components.utils.import("resource://yoono/yoonoCookies.js");
var gAccountSelector = {
get _btn () {
delete this._btn;
this._btn = document.getElementById("urlbar-account-selector");
return this._btn;
},
get _btnName () {
delete this._btnName;
this._btnName = document.getElementById("account-selector-name");
return this._btnName;
},
get _btnIcon () {
delete this._btnIcon;
this._btnIcon = document.getElementById("account-selector-icon");
return this._btnIcon;
},
get _popup () {
delete this._popup;
this._popup = document.getElementById("account-selector-popup");
return this._popup;
},
get _sessionList () {
delete this._sessionList;
return this._sessionList = document.getElementById("account-selector-popup-list");
return this._sessionList;
},
get _sessionTemplate () {
delete this._sessionTemplate;
return this._sessionTemplate = document.getElementById("account-selector-session-template");
return this._sessionTemplate;
},
get _deck () {
delete this._deck;
return this._deck = document.getElementById("account-selector-popup-innerbox");
return this._deck;
},
get _formName () {
delete this._formName;
return this._formName = document.getElementById("account-selector-form-name");
return this._formName;
},
get _formHome () {
delete this._formHome;
return this._formHome = document.getElementById("account-selector-form-homepage");
return this._formHome;
},
get _formAvatar () {
delete this._formAvatar;
return this._formAvatar = document.getElementById("account-selector-form-avatar");
return this._formAvatar;
},
get _bundle () {
delete this._bundle;
return this._bundle = document.getElementById("account-selector-bundle");
return this._bundle;
}
};
gAccountSelector.getNetworkNameId = function (id) {
if (id==1)
return "twitter";
else if (id==2)
return "facebook";
else if (id==3)
return "myspace";
else if (id==4)
return "flickr";
else if (id==5)
return "friendfeed";
else if (id==6)
return "imeem";
else if (id==7)
return "viadeo";
else if (id==8)
return "yoono";
else if (id==9)
return "linkedin";
else if (id==10)
return "aimmessenger";
else if (id==11)
return "googletalk";
else if (id==12)
return "livemessenger";
else if (id==13)
return "yahoomessenger";
return "";
}
gAccountSelector.getNetworkHome = function (id) {
if (id==1)
return "http://twitter.com";
else if (id==2)
return "http://facebook.com";
else if (id==3)
return "http://myspace.com";
else if (id==4)
return "http://flickr.com";
else if (id==5)
return "http://friendfeed.com";
else if (id==6)
return "http://imeem.com";
else if (id==7)
return "http://viadeo.com";
else if (id==8)
return "http://yoono.com";
else if (id==9)
return "http://www.linkedin.com/home";
else if (id==10)
return "http://services.aol.fr/aim/";
else if (id==11)
return "http://www.google.com/talk/";
else if (id==12)
return "http://www.windowslive.fr/messenger/";
else if (id==13)
return "http://messenger.yahoo.com/";
return "";
}
gAccountSelector.onTabSelect = function () {
if (typeof gBrowser=="object")
browser = gBrowser.mCurrentBrowser;
else
browser = document.getElementById('website-iframe');
CookiesService.getSessionInfo(browser,
function (session) {
gAccountSelector._btn.className = session?"active":"inactive";
if (session) {
if (session.name)
gAccountSelector._btnName.setAttribute("value", session.name);
else
gAccountSelector._btnName.setAttribute("value", gAccountSelector._bundle.getString("accountSelector.signIn"));
gAccountSelector._btnName.hidden=false;
} else {
gAccountSelector._btnName.setAttribute("value", "");
gAccountSelector._btnName.hidden=true;
}
if (session) {
gAccountSelector._btnIcon.className = "account-network-icon "+gAccountSelector.getNetworkNameId(session.networkId);
if (session.avatar && (!session.networkId || session.networkId==-1)) {
gAccountSelector._btnIcon.src = session.avatar;
} else {
gAccountSelector._btnIcon.src = "";
}
} else {
gAccountSelector._btnIcon.className = "account-network-icon default";
gAccountSelector._btnIcon.src = "";
}
});
}
gAccountSelector.onPopupHidden = function() {
this._btn.removeAttribute("open");
}
gAccountSelector.onClick = function () {
// Avoid close/reopen on button click
if (this._popup.state=="open") return;
this._deck.firstChild.hidden = false;
this._deck.lastChild.hidden = true;
this._popup.popupBoxObject.setConsumeRollupEvent(Components.interfaces.nsIPopupBoxObject.ROLLUP_CONSUME);
this._btn.setAttribute("open","true");
if (typeof YNPREFBRANCH=="object")
YNPREFBRANCH.setBoolPref("warnedOnAccounts",true);
var sessionList = this._sessionList;
while(sessionList.firstChild)
sessionList.removeChild(sessionList.firstChild);
CookiesService.getAllSessions(
function (sessions) {
gAccountSelector._popup.hidden = false;
var currentSessionId;
if (typeof gBrowser=="object")
currentSessionId = CookiesService.getSessionId(gBrowser.mCurrentBrowser);
else
currentSessionId = CookiesService.getSessionId(document.getElementById('website-iframe'));
try {
if (typeof gBrowser=="object") {
var domSession = gAccountSelector.getOneSessionDOMElement({name:gAccountSelector._bundle.getString("accountSelector.globalProfile")});
if (!currentSessionId)
domSession.setAttribute("selected","true");
sessionList.appendChild(domSession);
}
for(var i=0; i<sessions.length; i++) {
if (!sessions[i].name) continue; // Ignore temporary sessions
var domSession = gAccountSelector.getOneSessionDOMElement(sessions[i]);
if (sessions[i].id == currentSessionId)
domSession.setAttribute("selected","true");
sessionList.appendChild(domSession);
}
} catch(e) {
Components.utils.reportError(e);
}
gAccountSelector._popup.openPopup(gAccountSelector._btn, "after_start");
});
}
gAccountSelector.getOneSessionDOMElement = function (session) {
var box = this._sessionTemplate.cloneNode(true);
box.session = session;
box.hidden = false;
if (!session.id)
box.className = "account-selector-session global-profile";
var name = box.getElementsByClassName("account-selector-session-name")[0];
name.setAttribute("value", session.name);
var avatar = box.getElementsByClassName("account-selector-session-avatar")[0];
if (session.avatar)
avatar.setAttribute("src", session.avatar);
else
avatar.setAttribute("src", "chrome://yoono/skin/account-selector/icon_default_profile_20.png");
var network = box.getElementsByClassName("account-selector-session-network")[0];
if (session.networkId && session.networkId!=-1) {
network.className = "account-selector-session-network account-network-icon "+gAccountSelector.getNetworkNameId(session.networkId);
} else {
network.className = "account-selector-session-network";
}
if (!session.id) {
var profileLink = box.getElementsByClassName("account-selector-session-profile")[0];
profileLink.hidden = true;
var pipe = box.getElementsByClassName("account-selector-session-pipe")[0];
pipe.hidden = true;
}
return box;
}
gAccountSelector.onSessionClick = function (event, domElement) {
var session = domElement.session;
var browser;
if (typeof gBrowser=="object")
browser = gBrowser.mCurrentBrowser;
else
browser = document.getElementById('website-iframe');
var classname = event.target.className;
if (classname!="account-selector-session-stack" &&
classname!="account-selector-session-avatar" &&
!classname.match("account-selector-session-network") &&
classname!="account-selector-session-name" &&
classname!="account-selector-session-profile" &&
classname!="account-selector-session-reload"
) return;
var onlyReload = classname=="account-selector-session-reload";
if (session.id) {
CookiesService.attachSessionToBrowser(browser, session.id, function () {
var homeURL = session.homepage;
if (!homeURL)
homeURL = gAccountSelector.getNetworkHome(session.networkId);
if (!onlyReload && homeURL) {
if (browser._originalLoadURIWithFlags) // bypass loadURI overload that reset selected account
browser._originalLoadURIWithFlags(homeURL);
else
browser.loadURI(homeURL, null, null);
} else {
var reloadFlags = Components.interfaces.nsIWebNavigation.LOAD_FLAGS_BYPASS_PROXY | Components.interfaces.nsIWebNavigation.LOAD_FLAGS_BYPASS_CACHE;
browser.reload(reloadFlags);
}
});
} else {
CookiesService.detachSessionFromBrowser(browser);
// BrowserReloadSkipCache();
var reloadFlags = Components.interfaces.nsIWebNavigation.LOAD_FLAGS_BYPASS_PROXY | Components.interfaces.nsIWebNavigation.LOAD_FLAGS_BYPASS_CACHE;
browser.reload(reloadFlags);
}
this._popup.hidePopup();
this.onTabSelect();
}
gAccountSelector.addNewProfile = function () {
this._deck.firstChild.hidden = true;
this._deck.lastChild.hidden = false;
}
gAccountSelector.formAdd = function () {
var name = this._formName.value;
var home = this._formHome.value;
var avatar = this._formAvatar.value;
this.formReset();
this._popup.hidePopup();
CookiesService.addCustomProfile(name, home, avatar,
function (sessionId) {
CookiesService.attachSessionToBrowser(browser, sessionId, function () {
var homeURL = home;
if (browser._originalLoadURIWithFlags) // bypass loadURI overload that reset selected account
browser._originalLoadURIWithFlags(homeURL);
else
browser.loadURI(homeURL, null, null);
});
});
}
gAccountSelector.formCancel = function () {
this.formReset();
}
gAccountSelector.formReset = function () {
this._deck.firstChild.hidden = false;
this._deck.lastChild.hidden = true;
this._formName.reset();
this._formHome.reset();
this._formAvatar.reset();
}
gAccountSelector.help = function () {
this._popup.hidePopup();
var helpURL = "http://www.yoono.com/help.html#profile_selector";
if (typeof gBrowser=="object")
gBrowser.selectedTab = gBrowser.addTab(helpURL);
else
document.getElementById('website-iframe').loadURI(helpURL,null,null);
}
var infoLayer = null;
gAccountSelector.displayInfoBubble = function () {
//TODO: safely load dependancies like: YNPREF vars
if (typeof gBrowser!="object") return; // Don't display this in yoono desktop
if (YNPREFBRANCH.getBoolPref("warnedOnAccounts")) return;
var scriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"].getService(Components.interfaces.mozIJSSubScriptLoader);
scriptLoader.loadSubScript("chrome://yoonosb/content/js/services/alerts/Layer.js");
// Hack : used by Layer for errors ...
YServices = YOONO_CMPT.getYServices();
if (infoLayer)
infoLayer.close();
infoLayer = new Layer();
infoLayer.setOpacityEffet(true);
infoLayer.resize(420,140);
infoLayer.move("relative-bottom",177,0,this._btn);
var css=[];
css.push('#main-box {position:absolute;left:0;top:0;width:420px;height:140px;}');
css.push('#border-box {font-family:Arial;font-size: 12px; position:absolute;top:8px;bottom:0;right:0;left:0; padding:15px; border: 2px solid black; background:white; -moz-border-radius: 5px;}');
css.push('#icon {float:left;margin-left:5px;width:38px;height:56px;background-image:url(chrome://yoono/skin/close-popup/i_icon.png);}');
css.push('#margin-box {margin-left: 60px; margin-right: 30px; margin-bottom: 40px;}');
css.push('#checkbox-line { padding: 3px; cursor: pointer; -moz-border-radius: 5px; color: white; background-image: url(chrome://yoono/skin/close-popup/button_bg.png); position: absolute; bottom: 10px; left: 75px; display: inline-block; padding-right: 10px;}');
css.push('#checkbox-line:hover #checkbox { background-image: url(chrome://yoono/skin/close-popup/coche.png); }');
css.push('#checkbox {cursor: pointer;float: left;margin-top:2px;border: 1px solid #c0c0c0;-moz-border-radius: 3px; width: 10px; height: 10px;}');
css.push('#checkbox-text {cursor: pointer;margin-left: 18px;color: white;}');
css.push('#button-ok { padding: 3px; cursor: pointer; -moz-border-radius: 5px; color: white; background-image: url(chrome://yoono/skin/close-popup/button_bg.png); position: absolute; bottom: 10px; right: 30px; text-align: center; width: 40px;}');
css.push('#top-arrow {position:absolute;top:0;left:20px; width:21px; height: 10px; background-image: url(chrome://yoono/skin/close-popup/up_arrow.png);}');
if (navigator.platform.indexOf('Mac')==0) {
css.push('#border-box{-moz-border-radius:0;top:0;} #top-arrow{display:none;}');
}
infoLayer.setStyleText(css.join(''));
var title = gAccountSelector._bundle.getString("accountSelector.infoTitle");
var text = gAccountSelector._bundle.getString("accountSelector.infoText");
var disable = gAccountSelector._bundle.getString("accountSelector.infoDisable");
var html=[];
html.push('<div id="main-box">');
html.push(' <div id="border-box">');
html.push(' <div id="button-ok">OK</div>');
html.push(' <div id="icon"></div>');
html.push(' <div id="checkbox-line" style="clear:both">');
html.push(' <div id="checkbox"></div><div id="checkbox-text">'+disable+'</div>');
html.push(' </div>');
html.push(' <div id="margin-box">');
html.push(' <strong>'+title+'</strong><br />');
html.push(' '+text+'<br/>');
html.push(' </div>');
html.push(' </div>');
html.push(' <div id="top-arrow"></div>');
html.push('</div>');
infoLayer.setContent(html.join(''));
infoLayer.show(function () {
var btn = infoLayer.getElementById('button-ok');
btn.addEventListener("click", function () {
infoLayer.close();
infoLayer=null;
},false);
var checkbox = infoLayer.getElementById('checkbox-line');
checkbox.addEventListener("click", function () {
YNPREFBRANCH.setBoolPref("warnedOnAccounts",true);
infoLayer.close();
infoLayer=null;
},false);
});
}
window.addEventListener("load",
function () {
window.removeEventListener("load",arguments.callee,false);
if (typeof gBrowser!="object") return; // No gBrowser on Yoono Desktop
var container = gBrowser.tabContainer;
container.addEventListener("TabSelect", function () {
gAccountSelector.onTabSelect();
}, false);
gAccountSelector.onTabSelect();
}, false);